package com.infore.siteManagement.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.infore.siteManagement.constant.BusinessConstant;
import com.infore.siteManagement.enums.ResultStatus;
import com.infore.siteManagement.util.ResultEntity;
import com.infore.siteManagement.service.IStationSystemService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "站点系统管理接口", tags = {"站点系统管理接口" })
@RestController
@RequestMapping("/stationSystem")
public class StationSystemController {

	@Autowired
	private IStationSystemService iStationSystemService;
	
    @ApiOperation(value = "批量新增用户站点", notes = "批量新增用户站点关联")
    @RequestMapping(value = "/addUserStations/ids", method = RequestMethod.POST)
    public @ResponseBody ResultEntity addUserStations(@RequestParam String userId,
            @RequestParam String stationIds, String token) {
        String[] stationIdsArr = stationIds.split(",");
        int resultIdt = iStationSystemService.addUserStations(userId, stationIdsArr);
        if (resultIdt == -1) {
            return new ResultEntity(ResultStatus.ERROR, BusinessConstant.USER_NOT_EXIST);
        } else if (resultIdt == -2) {
            return new ResultEntity(ResultStatus.ERROR, BusinessConstant.PERMISSION_NOT_EXIST);
        } else if (resultIdt == -3) {
            return new ResultEntity(ResultStatus.ERROR, BusinessConstant.PERMISSION_ROLE_EXIST);
        } else if (resultIdt == -4) {
            return new ResultEntity(ResultStatus.ERROR, BusinessConstant.DATA_ERROR);
        }
        return new ResultEntity(ResultStatus.SUCCESS, BusinessConstant.INSERT_SUCCESS);
    }
    
    @ApiOperation(value = "查询用户站点权限", notes = "查询用户站点权限信息")
    @RequestMapping(value = "/userStations", method = RequestMethod.GET)
    public @ResponseBody ResultEntity getUserStations(@RequestParam String userId, String token) {
        return new ResultEntity(ResultStatus.SUCCESS, BusinessConstant.QUERY_SUCCESS)
                .setDataList(iStationSystemService.getUserStations(userId));
    }
    
    @ApiOperation(value = "批量新增平台客户站点", notes = "批量新增平台客户站点关联")
    @RequestMapping(value = "/addPlatformCustomerStations/ids", method = RequestMethod.POST)
    public @ResponseBody ResultEntity addPlatformCustomerStations(@RequestParam String platformId,
            @RequestParam String stationIds, String token) {
        String[] stationIdsArr = stationIds.split(",");
        int resultIdt = iStationSystemService.addPlatformCustomerStations(platformId, stationIdsArr);
        if (resultIdt == -1) {
            return new ResultEntity(ResultStatus.ERROR, BusinessConstant.PLATFORM_NOT_EXIST);
        } else if (resultIdt == -2) {
            return new ResultEntity(ResultStatus.ERROR, BusinessConstant.PERMISSION_NOT_EXIST);
        } else if (resultIdt == -3) {
            return new ResultEntity(ResultStatus.ERROR, BusinessConstant.PERMISSION_ROLE_EXIST);
        } else if (resultIdt == -4) {
            return new ResultEntity(ResultStatus.ERROR, BusinessConstant.DATA_ERROR);
        }
        return new ResultEntity(ResultStatus.SUCCESS, BusinessConstant.INSERT_SUCCESS);
    }
    
    @ApiOperation(value = "查询平台站点权限", notes = "查询平台客户站点权限信息")
    @RequestMapping(value = "/platformStations", method = RequestMethod.GET)
    public @ResponseBody ResultEntity getPlatformCustomerStations(@RequestParam String platformId, String token) {
        return new ResultEntity(ResultStatus.SUCCESS, BusinessConstant.QUERY_SUCCESS)
                .setDataList(iStationSystemService.getPlatformCustomerStations(platformId));
    }
}
